<?php
/**
 * Holds class MimeType
 *
 * @author daantimmer
 *
 * @package Library
 */

/**
 * Interface for getting the mimetype that belongs to a certain filetype
 *
 * @author daantimmer
 */
class MimeType{

	private $disposition = array(

            'txt' => 'inline',
            'htm' => 'inline',
            'html' => 'inline',
            'php' => 'inline',
            'css' => 'inline',
            'js' => 'inline',
            'json' => 'inline',
            'xml' => 'inline',
            'swf' => 'inline',
            'flv' => 'inline',

	// images
            'png' => 'inline',
            'jpe' => 'inline',
            'jpeg' => 'inline',
            'jpg' => 'inline',
            'gif' => 'inline',
            'bmp' => 'inline',
            'ico' => 'inline',
            'tiff' => 'inline',
            'tif' => 'inline',
            'svg' => 'inline',
            'svgz' => 'inline',

	// archives
            'zip' => 'attachment',
            'rar' => 'attachment',
            'exe' => 'attachment',
            'msi' => 'attachment',
            'cab' => 'attachment',

	// audio/video
            'mp3' => 'inline',
            'qt' => 'inline',
            'mov' => 'inline',

	// adobe
            'pdf' => 'inline',
            'psd' => 'attachment',
            'ai' => 'attachment',
            'eps' => 'attachment',
            'ps' => 'attachment',

	// ms office
            'doc' => 'attachment',
            'rtf' => 'attachment',
            'xls' => 'attachment',
            'ppt' => 'attachment',

	// open office
            'odt' => 'attachment',
            'ods' => 'attachment',
	);

	private $mime_types = array(

            'txt' => 'text/plain',
            'htm' => 'text/html',
            'html' => 'text/html',
            'php' => 'text/html',
            'css' => 'text/css',
            'js' => 'application/javascript',
            'json' => 'application/json',
            'xml' => 'application/xml',
            'swf' => 'application/x-shockwave-flash',
            'flv' => 'video/x-flv',

	// images
            'png' => 'image/png',
            'jpe' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif',
            'bmp' => 'image/bmp',
            'ico' => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif' => 'image/tiff',
            'svg' => 'image/svg+xml',
            'svgz' => 'image/svg+xml',

	// archives
            'zip' => 'application/zip',
            'rar' => 'application/x-rar-compressed',
            'exe' => 'application/x-msdownload',
            'msi' => 'application/x-msdownload',
            'cab' => 'application/vnd.ms-cab-compressed',

	// audio/video
            'mp3' => 'audio/mpeg',
            'qt' => 'video/quicktime',
            'mov' => 'video/quicktime',

	// adobe
            'pdf' => 'application/pdf',
            'psd' => 'image/vnd.adobe.photoshop',
            'ai' => 'application/postscript',
            'eps' => 'application/postscript',
            'ps' => 'application/postscript',

	// ms office
            'doc' => 'application/msword',
            'rtf' => 'application/rtf',
            'xls' => 'application/vnd.ms-excel',
            'ppt' => 'application/vnd.ms-powerpoint',

	// open office
            'odt' => 'application/vnd.oasis.opendocument.text',
            'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
	);
	
	public function __get($var){
		$std = new stdClass();
		if(isset($this->mime_types[strtolower($var)])){
			$std->mime = $this->mime_types[strtolower($var)];
			$std->disp = $this->disposition[strtolower($var)];
			
			return $std;
		}
		$std->mime = $this->mime_types['txt'];
		$std->disp = $this->disposition['txt'];
		return $std;
	}
}